<template>
  <div class="todolist">
    <header>todolist</header>
    <todo-input @addItem="addItem"></todo-input>
    <todo-list
      :list="list"
      :completeList="completeList"
      @removeItem="removeItem"
    ></todo-list>
  </div>
</template>

<script>
import TodoInput from "./input.vue";
import TodoList from "./list.vue";

export default {
  data() {
    return {
      list: [
        {
          name: "吃饭",
          state: false,
        },
        {
          name: "睡觉",
          state: false,
        },
        {
          name: "看电视",
          state: false,
        },
      ],
      completeList: [],
      text: "",
    };
  },
  methods: {
    addItem(val) {
      this.list.push({
        name: val,
        state: false,
      });
    },
    removeItem(index) {
      this.completeList.push(this.list[index]);
      this.list.splice(index, 1);
    },
  },
  components: {
    TodoInput,
    TodoList,
  },
};
</script>

<style>
ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

p {
  padding: 0;
  margin: 0;
}

.todolist {
  width: 400px;
  height: 500px;
  margin: 80px auto;
  padding-top: 20px;
}

header {
  font-size: 28px;
  line-height: 40px;
  text-align: center;
}

.todo-input {
  display: flex;
  margin-bottom: 20px;
}

.todo-input input {
  flex: 1;
  height: 34px;
  margin-right: 20px;
  padding-left: 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
}

.todo-input button {
  width: 70px;
  height: 36px;
  background-color: #409eff;
  border: none;
  border-radius: 6px;
  color: #ffffff;
}

.todo-item {
  display: flex;
  height: 40px;
  padding: 0 10px;
}

.todo-item span {
  padding-right: 10px;
}

.todo-item p {
  flex: 1;
}

.todo-item button {
  width: 50px;
  height: 32px;
  background-color: red;
  border: none;
  border-radius: 6px;
  color: #ffffff;
}

.todo-none {
  font-size: 20px;
  line-height: 80px;
  text-align: center;
  color: #409eff;
}
</style>
